package Classic150;

public class 有效的数独 {
    /*
        模拟，二维数组记录判断
     */
    public boolean isValidSudoku(char[][] board) {
        int[][] row = new int[9][10];
        int[][] col = new int[9][10];
        int[][] matrix = new int[9][10];
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                char c = board[i][j];
                if (c == '.') continue;
                int num = c - '0';
                if (row[i][num] == 1 || col[j][num] == 1 ||
                        matrix[(i / 3) * 3 + j / 3][num] == 1) return false;
                row[i][num] = 1;
                col[j][num] = 1;
                matrix[(i / 3) * 3 + j / 3][num] = 1;
            }
        }
        return true;
    }
}
